1 Introduction

This notebook highlights the problems that colorblind people are facing by using common colormaps, such as “Rainbow” or “Heat”, for element maps of minerals. Plotting mineral maps “through the eyes of colorblind people” shows that the same color occurs at least twice in a given range, representing completely different values. As shown below, those issues, which puts roughly xx% of the population at a disadvantage, can be mitigated by using colormaps like viridis that designed in way that those color repetition don’t occur.

I tend to only load the tidyverse packages at the beginning of a notebook. Functions from other packages are loaded explicitly. This helps me to remember which function is from which package.

library(tidyverse)
# require(cowplot)
# require(colorblindcheck)

Install required packages for the this project. colorspace and colorblindr simulate the colormaps the way colorblind people see them. The geochem package includes plotting functions for element maps.

# install.packages("colorspace", repos = "http://R-Forge.R-project.org")
# remotes::install_github("clauswilke/colorblindr")
# remotes::install_github("muhohl/geochem")

2 Comparison of Colormaps

A simple comparison of the three different colormaps and how they are perceived by colorblind people.

2.1 Rainbow

rainbow_palette <- rev(c("#CCCCCC", "#8B0000", "#FF0000", "#FFA500",
                     "#FFFF00", "#00FF00", "#90EE90",
                     "#ADD8E6", "#00008B",  "#A020F0", "#000000"))
colorblindcheck::palette_check(rainbow_palette, plot = TRUE, )

The popular Rainbow colormap. Both for Protanopia and Tritanopia black colors occur at least twice in each color range.

2.2 Heat

heat_palette <- rev(c("#FFFF00", "#FFA500", "#FF0000", "#8B0000", "#000000"))
colorblindcheck::palette_check(heat_palette, plot = TRUE)

Another common colormap using yellow for high values, for low values red and the lowest are in black. Red and black colors are difficult to distinguish for people suffering from Deuteranopia and Protanopia.

2.3 Viridis (C)

colorblindcheck::palette_check(viridis::viridis(11), plot = TRUE)

Example of the viridis color scale shows clearly distinguishable colors for all three types of colorblindness. The viridis colormap includes four different scales (A, B, C, D), with the here shown C type being the most popular one.

3 Element Maps

Loading the data frame, containing the image data.

df_element_map <- read_csv("Image_data.csv")

Comparison between different colormaps for selected elements.

3.1 Rainbow Map

i <- 1
rainbow_element_maps <- list()
for (element in names(df_element_map[-c(1:2)])) {
    p.rainbow <- ggplot(data = df_element_map,
                aes(x, y,
                    fill = !!sym(element))) +
    geom_raster(interpolate = TRUE) +
    coord_fixed(ratio = 1) +
    scale_y_discrete(expand = c(0,0)) +
    scale_x_discrete(expand = c(0,0)) +
    labs(fill = "",
         y = "",
         x = "") +
    ggtitle(paste(element, "ppm")) +
    scale_fill_gradientn(colors = rainbow_palette,
                         trans = "log",
                         breaks = c(1, 10, 100, 1000, 10000),
                         labels = scales::label_scientific()) +
    theme_bw() +
    theme(panel.border = element_blank(),
          text = element_text(family = "serif",
                              size = 16)) +
    guides(fill = guide_colorbar(barwidth = unit(1, "lines"),
                                 barheight = unit(8, "lines"),
                                 ticks.colour = "black", 
                                 frame.colour = "black"))
    rainbow_element_maps[[i]] <- p.rainbow
    i <- i+1
}
p.g.rainbow <- cowplot::plot_grid(plotlist = rainbow_element_maps)
p.g.rainbow

3.2 Heat Map

i <- 1
heat_element_maps <- list()
for (element in names(df_element_map[-c(1:2)])) {
    p.rainbow <- ggplot(data = df_element_map,
                aes(x, y,
                    fill = !!sym(element))) +
    geom_raster(interpolate = TRUE) +
    coord_fixed(ratio = 1) +
    scale_y_discrete(expand = c(0,0)) +
    scale_x_discrete(expand = c(0,0)) +
    labs(fill = "",
         y = "",
         x = "") +
    ggtitle(paste(element, "ppm")) +
    scale_fill_gradientn(colors=heat_palette,
                         trans = "log",
                         breaks = c(1, 10, 100, 1000, 10000),
                         labels = scales::label_scientific()) +
    theme_bw() +
    theme(panel.border = element_blank(),
          text = element_text(family = "serif",
                              size = 16)) +
    guides(fill = guide_colorbar(barwidth = unit(1, "lines"),
                                 barheight = unit(8, "lines"),
                                 ticks.colour = "black", 
                                 frame.colour = "black"))
    heat_element_maps[[i]] <- p.rainbow
    i <- i+1
}
p.g.heat <- cowplot::plot_grid(plotlist = heat_element_maps)
p.g.heat

3.3 Viridis Map (C)

viridis_d_element_maps <- 
    geochem::laser_map(data = df_element_map, 
                       selected_elements = names(df_element_map[-c(1:2)]),
                       fontsize = 16)
cowplot::plot_grid(plotlist = viridis_d_element_maps)

#gt <- ggplotGrob(rainbow_element_maps[[1]])
#leg <- gtable::gtable_filter(gt, "guide-box")
#leg[[1]][[1]][[1]][[1]][[1]][[2]]$height
#gt$grobs[[8]][[1]][[1]]$grobs[[5]]$gp$col <- "black"
#gt$grobs

3.4 Viridis Map (B)

viridis_b_element_maps <- 
    geochem::laser_map(data = df_element_map, 
                       selected_elements = names(df_element_map[-c(1:2)]),
                       option = "B", fontsize = 16)
cowplot::plot_grid(plotlist = viridis_b_element_maps)

3.5 Comparison of Maps

cowplot::plot_grid(
   cowplot::plot_grid(plotlist = heat_element_maps[c(2,4:5)],
                      ncol = 1),
   cowplot::plot_grid(plotlist = rainbow_element_maps[c(2,4:5)],
                      ncol = 1),
   cowplot::plot_grid(plotlist = viridis_d_element_maps[c(2,4:5)],
                      ncol = 1),
   cowplot::plot_grid(plotlist = viridis_b_element_maps[c(2,4:5)],
                      ncol = 1),
   ncol = 4,
   labels = c("Heat", "Rainbow", "Viridis (C)", "Viridis (B)")
   )

3.6 Colorblind Rainbow

cowplot::plot_grid(rainbow_element_maps[[4]],
                   colorblindr::cvd_grid(plot = rainbow_element_maps[[4]]),
                   nrow = 2, rel_heights = c(0.33, 0.67))

cowplot::plot_grid(rainbow_element_maps[[5]],
                   colorblindr::cvd_grid(plot = rainbow_element_maps[[5]]),
                   nrow = 2, rel_heights = c(0.33, 0.67))

Concentration of As are very low in the core of the pyrite and high in the zonation of the rim.

3.7 Colorblind Heat

cowplot::plot_grid(heat_element_maps[[5]],
                   colorblindr::cvd_grid(plot = heat_element_maps[[5]]),
                   nrow = 2, rel_heights = c(0.33, 0.67))

cowplot::plot_grid(viridis_b_element_maps[[5]],
                   colorblindr::cvd_grid(plot = viridis_b_element_maps[[5]]),
                   nrow = 2, rel_heights = c(0.33, 0.67)
)

3.8 Colorblind Viridis (C)

cowplot::plot_grid(viridis_d_element_maps[[4]],
                   colorblindr::cvd_grid(plot = viridis_d_element_maps[[4]]),
                   nrow = 2, rel_heights = c(0.33, 0.66)
                   )

cowplot::plot_grid(viridis_d_element_maps[[5]],
                   colorblindr::cvd_grid(plot = viridis_d_element_maps[[5]]),
                   nrow = 2, rel_heights = c(0.33, 0.66)
                   )

4 Session Info

sessionInfo()
## R version 4.0.4 (2021-02-15)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Pop!_OS 21.04
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
## 
## locale:
##  [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8    
##  [5] LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8   
##  [7] LC_PAPER=en_AU.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] forcats_0.5.0   stringr_1.4.0   dplyr_1.0.7     purrr_0.3.4    
## [5] readr_1.4.0     tidyr_1.1.2     tibble_3.1.5    ggplot2_3.3.5  
## [9] tidyverse_1.3.0
## 
## loaded via a namespace (and not attached):
##  [1] viridis_0.5.1         httr_1.4.2            sass_0.4.0           
##  [4] jsonlite_1.7.2        viridisLite_0.4.0     carData_3.0-4        
##  [7] modelr_0.1.8          bslib_0.3.1           assertthat_0.2.1     
## [10] cellranger_1.1.0      yaml_2.2.1            pillar_1.6.4         
## [13] backports_1.2.0       glue_1.4.2            digest_0.6.28        
## [16] ggsignif_0.6.1        rvest_0.3.6           colorspace_2.0-2     
## [19] cowplot_1.1.1         htmltools_0.5.2       pkgconfig_2.0.3      
## [22] broom_0.7.2           haven_2.3.1           colorblindcheck_1.0.0
## [25] bookdown_0.22         scales_1.1.1          openxlsx_4.2.3       
## [28] rio_0.5.16            generics_0.1.0        farver_2.1.0         
## [31] car_3.0-10            ellipsis_0.3.2        ggpubr_0.4.0         
## [34] withr_2.4.2           cli_3.0.1             magrittr_2.0.1       
## [37] crayon_1.4.1          readxl_1.3.1          evaluate_0.14        
## [40] fs_1.5.0              fansi_0.5.0           rstatix_0.6.0        
## [43] xml2_1.3.2            foreign_0.8-81        tools_4.0.4          
## [46] data.table_1.13.2     hms_0.5.3             lifecycle_1.0.1      
## [49] spacesXYZ_1.1-1       munsell_0.5.0         reprex_0.3.0         
## [52] zip_2.1.1             ggsci_2.9             geochem_0.0.0.9000   
## [55] compiler_4.0.4        jquerylib_0.1.4       rlang_0.4.12         
## [58] grid_4.0.4            rstudioapi_0.13       colorblindr_0.1.0    
## [61] labeling_0.4.2        rmarkdown_2.8         gtable_0.3.0         
## [64] abind_1.4-5           DBI_1.1.0             curl_4.3             
## [67] R6_2.5.1              gridExtra_2.3         lubridate_1.7.9.2    
## [70] knitr_1.30            fastmap_1.1.0         utf8_1.2.2           
## [73] stringi_1.7.5         Rcpp_1.0.7            vctrs_0.3.8          
## [76] dbplyr_2.0.0          tidyselect_1.1.1      xfun_0.22